// pages/home/home.js
import request from '../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banners:[],
    recommendList:[],
    topList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
   onLoad(options) {
   this.getBanners()
   this.getRecommendList()
   this.getTopList()
  },
  // 请求轮播图
  async getBanners(){
    const result = await request('/banner',{type:2})
    this.setData({
     banners:result.banners
   })
  },
  // 请求推荐歌单
  async getRecommendList(){
    const re = await request("/personalized",{limit:15})
    // console.log(re);
    this.setData({
      recommendList:re.result
    })
  },
  // 请求排行榜
  async getTopList(){
    let index = 0
    const topList = []
    while(index<5){
      const re = await request('/top/list',{idx:index++})
      // console.log(re);
      const topListItem = {
        name : re.playlist.name,
        tracks : re.playlist.tracks.slice(0,3)
      }
      topList.push(topListItem)
    }
    this.setData({
      topList
    })
  },
  // 点击去每日推荐
  toRecommend(){
    wx.navigateTo({
      url: '/subpackages/recommend/recommend',
    })
  },


})